<style>
.comment-edit-textarea {
    position: absolute;
    top: 0px;
    left: 0px;
    right: 0px;
    bottom: 50px;
    width: inherit;
}

.comment-edit-bottom {
    position: absolute;
    bottom: 10px;
    right: 10px;
}

.comment-edit-bottom button {
    width: 80px;
}
</style>

<div class="card">
    <div class="col-md-12">
        <textarea autoHeight=true class="no-outline comment-edit-textarea" id="commentUpdateContent">{{comment.content}}</textarea>

        <div class="comment-edit-bottom">
            <input type="file" id="commentFilePicker2" class="hide" multiple />
            <div class="float-right">
                <button class="btn btn-default attachment-btn">添加附件</button>
                <button class="btn" id="updateCommentBtn">更新</button>
            </div>
        </div>
    </div>
</div>

<script type="text/javascript">
    $(function () {

        function appendToEditBox(appendText) {
            var oldValue = $("#commentUpdateContent").val();
            if (oldValue != "") {
                oldValue += "\n"
            }
            $("#commentUpdateContent").val(oldValue + appendText);
        }

        $("#updateCommentBtn").click(function (e) {
            var params = {};
            params.p = "update";
            params.comment_id = "{{comment.id}}";
            params.content = $("#commentUpdateContent").val();
            $.post("/note/comment", params, function (resp) {
                if (resp.code == "success") {
                    xnote.toast("更新成功");
                    xnote.fire("comment.refresh");
                    xnote.fire("comment.closeEditDialog");
                } else {
                    xnote.alert(resp.message);
                }
            });
        });

        $(".attachment-btn").click(function (e) {
            $("#commentFilePicker2").click();
        });

        xnote.createUploaderEx({
            fileSelector: "#commentFilePicker2",
            chunked: false,
            successFn: function (resp) {
                console.log("文件上传成功", resp);
                var link = "file://" + resp.webpath;
                appendToEditBox(link);
            },
            fixOrientation: true
        });

        // 通过剪切板上传
        $("#commentUpdateContent").on("paste", function (e) {
            xnote.requestUploadByClip(e, "msg", function (respJson) {
                console.log(respJson);
                var link = "file://" + respJson.webpath;
                appendToEditBox(link);
            });
        });
    });
</script>